extends Node

var list:Array
var index:int

func _ready(): 
	if ObjectManager.is_replay:
		ObjectManager.toast.showToast("开始复盘")
		loadManual()
		playNext()
		$Timer.start()

func loadManual():
	list = load(DataStorageManager.path_manual).data

# 定时500ms 开始播放
func playNext():
	if index == list.size():
		$Timer.stop()
		return
	var s = list.get(index)
	index += 1
	var obj = JSON.parse_string(s)
	WebSocketManager.on_receive(obj)
	# 如果是刷新什么的话，建议再调用一次playNext
	var method = obj.method as String
	match method:
		"gameStart":
			$Timer.stop()
			await get_tree().create_timer(1).timeout
			$Timer.start()
		"switchTurnPlay":
			ObjectManager.toast.showToast("回合切换")
		"update_small","update_big","update_point","big_die","small_die":
			playNext()

func _on_timer_timeout() -> void:
	playNext()
